package com.dbsun.controller.st;

import com.dbsun.base.BaseController;
import com.dbsun.common.ServerResponse;
import com.dbsun.entity.system.Page;
import com.dbsun.entity.system.PageData;
import com.dbsun.mapper.CommentconfigMapper;
import com.dbsun.mapper.HomeworkMapper;
import io.swagger.annotations.Api;
import com.dbsun.service.st.CommentService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Api(value = "comment", description = "公告管理", tags = "公告管理")
@Controller
@RequestMapping("/comment")
public class CommentController extends BaseController {
    @Autowired
    private CommentService sCommentService;

    @Autowired
    private CommentconfigMapper commentconfigMapper;

    @Autowired
    private HomeworkMapper homeworkMapper;

    @RequestMapping(value = "/gosCommentPage", method = RequestMethod.GET)
    @ApiOperation(value = "跳转到公告管理页面")
    public String gosCommentPage() {
        return "";
    }

    @RequestMapping(value = "/getHomeWork", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取作业设置")
    @ApiImplicitParams({
    })
    public JSONObject getHomeWork() {
        PageData pageData = homeworkMapper.getHomeWork(new PageData());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("info",pageData);
        return jsonObject;
    }

    @RequestMapping(value = "/updateHomeWork", method = RequestMethod.GET)
    @ApiOperation(value = "更改作业设置")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "info", value = "公告管理", required = false, dataType = "String"),
    })
    public PageData updateHomeWork() {
        PageData pd = this.getPageData();
        homeworkMapper.updateHomework(pd);
        return new PageData();
    }

    @RequestMapping(value = "/getPagesCommentList", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取公告管理列表数据", notes = "分页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "showCount", value = "每页记录数", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "currentPage", value = "当前页", required = true, dataType = "String"),
    })
    public JSONObject getPagesCommentList() {
        PageData pd = this.getPageData();
        Page page = this.getPage();
        page.setPd(pd);
        List<PageData> sCommentList = null;
        try {
            sCommentList = sCommentService.getPageCommentList(page);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return viewReturnPageData(page, sCommentList);
    }

    @RequestMapping(value = "/addsComment", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "添加公告管理", notes = "添加不为空的内容")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "title", value = "公告管理", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "content", value = "内容", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "url", value = "封面", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "s_id", value = "发布者", required = false, dataType = "String"),
    })
    public ServerResponse addsComment() {
        PageData pd = this.getPageData();
        PageData userPd = this.getUserPd();
        return sCommentService.addComment(this.putUserPd(pd));
    }

    @RequestMapping(value = "/updatesComment", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "更新公告管理", notes = "更新不为空的内容")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "xxx", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "title", value = "公告管理", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "content", value = "内容", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "url", value = "封面", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "s_id", value = "发布者", required = false, dataType = "String")
    })
    public ServerResponse updatesCommentByid() {
        PageData pd = this.getPageData();
        PageData userPd = this.getUserPd();
        return sCommentService.updateCommentByid(pd);
    }

    @RequestMapping(value = "/getsCommentList", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取公告管理列表数据非分页方法")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "xxx", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "title", value = "公告管理", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "content", value = "内容", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "url", value = "封面", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "s_id", value = "发布者", required = false, dataType = "String")
    })
    public ServerResponse getsCommentList() {
        PageData pd = this.getPageData();
        PageData userPd = this.getUserPd();
        return sCommentService.getCommentList(pd);
    }

    @RequestMapping(value = "/getsCommentByColumn", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取公告管理单条数据(通过任意列)")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "xxx", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "title", value = "公告管理", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "content", value = "内容", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "url", value = "封面", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "s_id", value = "发布者", required = false, dataType = "String")
    })
    public ServerResponse getsCommentByColumn() {
        PageData pd = this.getPageData();
        PageData userPd = this.getUserPd();
        return sCommentService.getCommentByColumn(pd);
    }

    @RequestMapping(value = "/deletesComment", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "删除公告管理", notes = "删除不为空的内容")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "xxx", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "title", value = "公告管理", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "content", value = "内容", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "url", value = "封面", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "s_id", value = "发布者", required = false, dataType = "String")
    })
    public ServerResponse deletesCommentByColumn() {
        PageData pd = this.getPageData();
        return sCommentService.deleteCommentByColumn(pd);
    }
}
